<?php
require('includes/top.php');
$userno = $_POST['userno'];
$user_type = $_POST['user_type'];
$user_fname = $_POST['user_fname'];
$user_lname = $_POST['user_lname'];
$user_address = $_POST['user_address'];
$user_telno = $_POST['user_telno'];
$user_email = $_POST['user_email'];

if($_POST['user_name']=="" || $_POST['user_password']=="")
{
$user_name = $_POST['userno'];
$user_password = $_POST['userno'];
}
else
{
$user_name = $_POST['user_name'];
$user_password = $_POST['user_password'];
}
$user_desn = $_POST['user_desn'];
$depot = $_POST['depot'];

$query = "SELECT * FROM users WHERE `user_no` = '".$userno."'";
$result = mysql_query($query);
if ( mysql_num_rows ( $result )> 0 )
{
    header("location: registration?v=err");
}
else
 {
$sql1="INSERT INTO users(`user_groups_id`,`user_no`,`user_firstname`,`user_lastname`,`user_telno`,`user_address`,`user_email_address`,`user_password`,`user_name`,`user_designation`,`depot`) VALUES ($user_type,'$userno','$user_fname','$user_lname','$user_telno','$user_address','$user_email','$user_password','$user_name','$user_desn','$depot')";
$result1=mysql_query($sql1);
}

if($result1>0)
{

// recipients
$to  = $user_email; // 
// subject
$subject = 'Login Details';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p><strong>Following is your Login Details:</strong></p>
  <table>
    <tr>
      <td>Username:</td><td>'.$user_name.'</td>
    </tr>
    <tr>
      <td>Password:</td><td>'.$user_password.'</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To:' . $to . "\r\n";
$headers .= 'From: no-reply@laptrak.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

header('Location: registration.php?v=success');
}
else
{
header('Location: registration.php?v=err');
}
?>